package com.k.kc.util.regex;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 正则表达式
 *
 *  Java use
 *    String inputContent = "";
 *    boolean result = Pattern.matches(regStr, inputContent);
 *    or
 *    Pattern p = Pattern.compile(regStr);
 *    Matcher m = p.matcher(inputContent);
 *    boolean result2 = m.matches();
 *
 *   Javascript use
 *     const inputContent = "";
 *     var reg = new RegExp("^[^\'\\\"\<\>\%\&\s]+$");
 *     reg.test(inputContent);
 *     or
 *     var reg = /^[^\'\\\"\<\>\%\&\s]+$/;
 *     reg.test(inputContent);
 *
 * @author k
 */
public class RegExConst {
    /**
     * [数字][1-3600]
     */
    public final static String REGEX_NUM_1_3600 = "^([1-9]\\d{0,2}|[1-2]\\d{3}|[3][0-5]\\d{2}|3600)$";

    /**
     * [数字][1-4095]
     */
    public final static String REGEX_NUM_1_4095 = "[1-9]\\d{0,2}+|[1-4]\\d(?<!4[1-9])\\d\\d(?<!409[6-9])";

    /**
     * [IP][非回环IP]
     */
    public final static String REGEX_IP_NoLoop = "^((?!127)[\\d]{1,3})\\.([0-9]|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])\\.([0-9]|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])\\.([0-9]|[1-9]\\d|1\\d\\d|2[0-4]\\d|25[0-5])$";

    /**
     * [PORT]
     */
    public final static String REGEX_PORT = "^([0-9]|[1-9]\\d|[1-9]\\d{2}|[1-9]\\d{3}|[1-5]\\d{4}|6[0-4]\\d{3}|65[0-4]\\d{2}|655[0-2]\\d|6553[0-5])$";

    /**
     * [数字]
     */
    public final static String REGEX_DIGIST = "^\\d";

    /**
     * [数字] 非零开头 10位内
     */
    public final static String regx = "^[1-9]\\d{0,10}";

    /**
     * 非0开头的正整数
     */
    public final static String regx_digits = "^([1-9][0-9]*)$";

    /**
     * [英文 数字 下划线]
     */
    public final static String regx_name = "^([a-zA-Z0-9_]+)$";

    /**
     * [中文 英文 数字 _]
     */
    public final static String regx_name_2 = "^([\\u4E00-\\uFA29]|[a-zA-Z0-9_]+)$";

    /**
     * 包含 [中文 英文 数字 _ -] 1-20位
     */
    public final static String regx_name_3 = "^([\\u4E00-\\uFA29]|[a-zA-Z0-9_-]){1,20}$";

    /**
     * 不能包含 [\ ' " % < > 空格]
     * js:
     * var reg = new RegExp("^[^\'\\\"\<\>\%\&\s]+$");
     * reg.test("inputValue");
     * or
     * var reg = /^[^\'\\\"\<\>\%\&\s]+$/;
     * reg.test("inputValue");
     */
    public final static String REGEX_exclude_name = "^[^\\'\\\\\\\"\\<\\>\\%\\&\\s]+$";

    public static void main(String[] args) {
        String inputContent = "ljw";
        String regStr = "";
        // Java use
        boolean result = Pattern.matches(regStr, inputContent);
        // Java use2
        Pattern p = Pattern.compile(regStr);
        Matcher m = p.matcher(inputContent);
        boolean result2 = m.matches();

        // Js use
        //const regEx = "^([1-9]\d{0,2}|[1-2]\d{3}|[3][0-5]\d{2}|3600)$";
        //const inputContent = "abc";
        //const reg = new RegExp(regEx);
        //const r = reg.test(inputContent);
        //console.log(r);

    }
}
